<template>
  <card :header="false">
    <template #filter>
      <el-form :inline="true" :model="searchForm" class="demo-form-inline">
        <el-form-item label="单据类型">
          <el-select
            v-model="searchForm.lngreceipttypeid"
            clearable
            filterable
            placeholder="请选择"
          >
            <el-option
              v-for="(item,index) in optionList"
              :key="index"
              :label="item.strreceipttypename"
              :value="item.lngreceipttypeid"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="searchSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </template>
    <el-table
      ref="table"
      :data="tableData3"
      tooltip-effect="dark"
      style="width: 100%"
      :header-cell-style="{background:'#F5F4F7'}"
      border
      stripe
      highlight-current-row
      :height="tableHeight"
    >
      <el-table-column
        type="index"
        width="60"
        align="center"
        :index="indexMethod"
        label="序号"
        sortable
      />

      <el-table-column
        prop="strreceipttypename"
        label="单据类型"
        min-width="220"
      />
      <el-table-column
        prop="blnisprintshow"
        label="打印规则"
        min-width="220"
      />
      <el-table-column
        prop="blnprintmoreshow"
        label="打印次数"
        min-width="220"
      />
      <el-table-column label="操作" align="center" width="160" class-name="mb0">
        <template slot-scope="scope">
          <el-button type="text" @click="handleUpdate(scope.$index,scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      v-if="paging.total > 0"
      background
      :current-page.sync="paging.page"
      :page-sizes="[10, 20, 30, 40]"
      :page-size.sync="paging.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="paging.total"
      @size-change="getList"
      @current-change="getList"
    />
    <!-- Form -->
    <!-- <el-button type="text" @click="dialogFormVisible = true">打开嵌套表单的 Dialog</el-button> -->

    <el-dialog title="编辑" :visible.sync="dialogFormVisible" width="500px">
      <el-form :model="form">
        <el-form-item label="单据类型" :label-width="formLabelWidth">
          <el-input v-model="form.strreceipttypename" autocomplete="off" disabled style="width:190px" />
        </el-form-item>
        <el-form-item label="打印规则" :label-width="formLabelWidth">
          <el-radio v-model="form.blnisprint" :label="0">只允许制单人打印</el-radio>
          <el-radio v-model="form.blnisprint" :label="1">查看人员均可打印</el-radio>
        </el-form-item>
        <el-form-item label="打印次数" :label-width="formLabelWidth">
          <el-radio v-model="form.blnprintmore" :label="0">允许多次打印</el-radio>
          <el-radio v-model="form.blnprintmore" :label="1">只允许打印1次</el-radio>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sure">确 定</el-button>
        <el-button @click="dialogFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </card>
</template>
<script>
import { queryList, edit, queryTypeList } from '@/api/system/print-setting'
import calculateCommonTableHeight from '@/layout/mixin/calculateCommonTableHeight'
export default {
  mixins: [calculateCommonTableHeight],
  props: {
    pageType: {
      type: Number,
      default: 1
    }
  },
  data() {
    return {
      tableData3: [],
      searchForm: {
        lngreceipttypeid: ''
      },
      optionList: [],
      // multipleSelection: [],
      dialogFormVisible: false,
      form: {

      },
      formLabelWidth: '80px',
      idx: 0,
      paging: {
        total: 2,
        page: 1,
        size: 10
      }
    }
  },
  created() {
    this.getList()
    this.queryTypeList()
  },
  methods: {
    // handleSelectionChange(val) {
    //   this.multipleSelection = val
    //   console.log(this.multipleSelection)
    // },
    searchSubmit() {
      this.paging.page = 1
      this.getList()
    },
    indexMethod(index) {
      index = (index + 1) + (this.paging.page - 1) * this.paging.size
      return index
    },

    getList() {
      queryList(this.searchForm, this.paging.page, this.paging.size).then(res => {
        if (res.code === 20000) {
          this.paging.total = res.data.total
          this.tableData3 = res.data.rows
        }
      })
    },
    handleUpdate($index, row) {
      this.dialogFormVisible = true
      this.form = Object.assign({}, row)
      this.idx = $index
    },
    queryTypeList() {
      queryTypeList({}).then(res => {
        if (res.code === 20000) {
          this.optionList = res.data
        }
      })
    },
    sure() {
      const tmp = {
        'lngreceiptprintid': this.form.lngreceiptprintid,
        'blnisprint': this.form.blnisprint,
        'blnprintmore': this.form.blnprintmore
      }
      edit(tmp).then(res => {
        if (res.code === 20000) {
          this.dialogFormVisible = false
          this.$message({
            showClose: true,
            message: '编辑成功！',
            type: 'success'
          })
          this.getList()
        }
      })
    }
  }
}
</script>
<style scoped>

</style>

